package cn.afterturn.easypoi.view;

import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.entity.vo.PDFTemplateConstants;
import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants;
import cn.afterturn.easypoi.entity.vo.TemplateWordConstants;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.pdf.entity.PdfExportParams;
import cn.afterturn.easypoi.test.entity.MsgClient;
import cn.afterturn.easypoi.test.entity.MsgClientGroup;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.afterturn.easypoi.word.entity.WordImageEntity;

@Controller
@RequestMapping("/pdfViewTest")
public class PDFExportViewTest {
	@RequestMapping("load")
    public void downloadByWordView(ModelMap modelMap, HttpServletRequest request,
                                      HttpServletResponse response) {
		 Field[] fields =  MsgClient.class.getFields();
	        for (int i = 0; i < fields.length; i++) {
	            Excel excel = fields[i].getAnnotation(Excel.class);
	            System.out.println(excel);
	        }
	        
	        List<MsgClient> list = new ArrayList<MsgClient>();
	        for (int i = 0; i < 10; i++) {
	            MsgClient client = new MsgClient();
	            client.setBirthday(new Date());
	            client.setClientName("小明" + i);
	            client.setClientPhone("18797" + i);
	            client.setCreateBy("JueYue");
	            client.setId("1" + i);
	            client.setRemark("测试" + i);
	            MsgClientGroup group = new MsgClientGroup();
	            group.setGroupName("测试" + i);
	            client.setGroup(group);
	            list.add(client);
	        }
	        Date start = new Date();
	        PdfExportParams params = new PdfExportParams("2412312",null);
	     modelMap.put("a", 11111111);
	     modelMap.put("b", 22222222);
	     modelMap.put("c", 333333333);
	     modelMap.put("d", 44444444);
	     
         modelMap.put(PDFTemplateConstants.FILE_NAME, "xxxxxxxxxxx");
         modelMap.put(PDFTemplateConstants.URL, "pdf/a.pdf");
         modelMap.put(PDFTemplateConstants.PARAMS, params);
         modelMap.put(PDFTemplateConstants.DATA_LIST, list);
         modelMap.put(PDFTemplateConstants.CLASS, MsgClient.class);
       // EasypoiTemplateWordView.render(modelMap, request, response, TemplateWordConstants.EASYPOI_TEMPLATE_WORD_VIEW);
         PoiBaseView.render(modelMap, request, response,
        		 PDFTemplateConstants.EASYPOI_PDF_TEMPLATE_VIEW);
		
	}
}
